import Data
import Generate_Password
from prettytable import PrettyTable


def Out_Table():
    """TODO: Docstring for Out_Table.
    :returns: TODO

    """
    x = PrettyTable(["编号", "操作", "说明"])
    x.align["编号", "操作", "说明"] = "c"
    x.add_row([1, "SELECT", "查询"])
    x.add_row([2, "INSERT", "插入"])
    x.add_row([3, "UPDATE", "修改"])
    x.add_row([4, "DELETE", "删除"])
    x.add_row([5, "Generate password", "生成密码"])
    x.add_row(['q', "Launch the program", "退出"])
    print(x)


def Select_Table():
    xs = PrettyTable(["编号", "操作", "说明"])
    xs.align["编号", "操作", "说明"] = "c"
    xs.add_row(["a", "SELECT_ALL", "查询所有"])
    xs.add_row([1, "TYPE", "类型"])
    xs.add_row(["q", "Launch the program", "退出"])
    print(xs)


def Update_Table():
    """TODO: Docstring for .

    :returns: TODO

    """
    x = PrettyTable(["编号", "操作", "说明"])
    x.align["编号", "操作", "说明"] = "c"
    x.add_row([1, "ID", "序号"])
    x.add_row([2, "Account", "账号"])
    x.add_row([3, "Type", "软件"])
    x.add_row(['q', 'Launch the program', '退出'])
    print(x)


if __name__ == "__main__":
    Out_Table()
    while True:
        print("ID: ")
        id = input("   >")
        if id == '1':
            while True:
                Select_Table()
                print("Select_ID:")
                id_1 = input(" >> ")
                if id_1 == 'a':
                    Data.Select()
                elif id_1 == '1':
                    Data.Select_Type()
                elif id_1 == 'q':
                    break
        elif id == '2':
            Data.Insert()
        ## 修改
        elif id == '3':
            while True:
                Update_Table()
                print("UPdate_ID:")
                id_2 = input("  >> ")
                if id_2 == '1':
                    Data.Select()
                    Data.Update_Id()
                elif id_2 == '2':
                    Data.Select()
                    Data.Update_Account()
                elif id_2 == '3':
                    Data.Select()
                    Data.Update_Type()
                elif id_2 == 'q':
                    Out_Table()
                    break
        ## 删除
        elif id == '4':
            Data.Select()
            Data.Delete()
        elif id == '5':
            print(Generate_Password.GenPassword(16))
            Out_Table()
        elif id == 'q':
            exit(0)
